﻿using AutoMapper;
using CommonType;
using MediatR;
using S_Incident.API.Application.Commands;
using S_Incident.Domains.WorkflowEngine;
using S_Incident.Infrasturctre.Interface;

namespace S_Incident.API.Application.CommandsHanders
{
    public class ProcessSqlSuageCreateCommandHanders : IRequestHandler<ProcessSqlSuageCreateCommand, ApiResule<int>>
    {
        private readonly IProcessRepository flowRepository;
        private readonly IMapper mapper;
        public ProcessSqlSuageCreateCommandHanders(IProcessRepository flowRepository, IMapper mapper)
        {
            this.flowRepository = flowRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 新增流程管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResule<int>> Handle(ProcessSqlSuageCreateCommand request, CancellationToken cancellationToken)
        {
            var res = mapper.Map<Process>(request);
            var result= await flowRepository.AddAsync(res);
            if (result > 0)
            {
                return new ApiResule<int>
                {
                    Code = 200,
                    Msg = "新增成功",
                    Result = result
                };
            }
            else
            {
                return new ApiResule<int>
                {
                    Code = 250,
                    Msg = "新增失败",
                    Result = result
                };
            }
        }
    }
}
